package com.elective.courseselect.serviceUtils;

import com.elective.courseselect.entity.StudentCourseEntity;
import com.elective.courseselect.service.*;
import com.elective.courseselect.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author lee
 * @date 2021年10月24日 21:10
 */
@Component
public class StuCourseUtils {

    public static UserUtils userUtils;


    @Autowired
    UserService userService;

    @Autowired
    CourseService courseService;

    @Autowired
    CourseCharacterService courseCharacterService;

    @Autowired
    CharacterService characterService;

    @Autowired
    CommentService commentService;

    @Autowired
    CommentingService commentingService;

    @Autowired
    CourseQuestionnaireService courseQuestionnaireService;

    @Autowired
    QuestionnaireService questionnaireService;

    @Autowired
    StudentCourseService studentCourseService;

    public static StuCourseUtils stuCourseUtils;

    @PostConstruct
    public void init(){
        stuCourseUtils=this;   //必需
        stuCourseUtils.userService=this.userService;
        stuCourseUtils.courseService=this.courseService;
        stuCourseUtils.courseCharacterService=this.courseCharacterService;
        stuCourseUtils.commentService=this.commentService;
        stuCourseUtils.commentingService=this.commentingService;
        stuCourseUtils.courseQuestionnaireService=this.courseQuestionnaireService;
        stuCourseUtils.questionnaireService=this.questionnaireService;
        stuCourseUtils.studentCourseService=this.studentCourseService;
    }


    public static StudentCourseEntity modifyStuCourse(StudentCourseEntity studentCourseEntity , Integer courseId) {
        if (null == studentCourseEntity.getCourseId().split(",")) {
            studentCourseEntity.setCourseId(courseId.toString());
        }else{
            String[] split = studentCourseEntity.getCourseId().split(",");
            Set<String> tempSet = new HashSet<>(Arrays.asList(split));
            tempSet.add(courseId.toString());
            String strip = ListUtils.strip(tempSet.toString());
            studentCourseEntity.setCourseId(strip);
            stuCourseUtils.studentCourseService.updateById(studentCourseEntity);
        }
        return studentCourseEntity;
    }

    public static void main(String[] args) {
        //HashSet<String> a = new HashSet<>();
        ArrayList<String> a = new ArrayList<>();
        a.add("1");
        a.add("2");
        a.add("3");
        String strip = ListUtils.strip(a.toString().trim());
        System.out.println(strip);

    }
}
